<?php
/**
 * 单页模块
 * 
 + ----------------------------------------------------- 
 * Date 2013-3-8
 + -----------------------------------------------------
 */
class SimpleAction extends CommonAction {
	
	public function index() {
		$mid=isset($_REQUEST['mid']) ? intval($_REQUEST['mid']) : 0 ;
		//当前栏目
		$menu_model=M("Menu");
		$curr_menu=$menu_model->getById($mid);
		$this->assign("curr_menu",$curr_menu);
		
		$Simple=M('Simple');
		$data=$Simple->where('menu_id='.$mid)->find();
		if(!$data['id']){
			$data=array(
				'menu_id'=>$mid,
				'name'=>$curr_menu['menu_name'],
				'content'=>'',
				'add_time'=>time()
			);
			if($insert_id=$Simple->add($data)){
				$data['id']=$insert_id;
			}
		}
		$this->assign('data',$data);
		
		$this->display();
		return;
    }
	
    
    public function update(){
    	$model = M('Simple');
    	if (false === $model->create()) {
    		$this->error($model->getError());
    	}
    	if (false !== $model->save()) {
    		$this->success(L('编辑成功'),$this->getReturnUrl());
    	} else {
    		$this->error(L('编辑失败'));
    	}
    }
}

?>